<script setup lang="ts">
import { ref } from 'vue'
import SubmitMCPDialog from './SubmitMCPDialog.vue'
import ajax from "../main.ts"
import { ElMessage } from 'element-plus'

const showSubmitDialog = ref(false)

const handleSubmit = async (data: { type: string; githubUrl: string }) => {
  if (!data.githubUrl) {
    ElMessage.error('GitHub地址不能为空')
    return
  }

  try {
    const res = await ajax.post('subMcp/', {
      type: data.type,
      githubUrl: data.githubUrl
    })
    
    if (res.data.code === 200) {
      ElMessage.success(res.data.msg)
      showSubmitDialog.value = false
    } else {
      ElMessage.error(res.data.msg || '提交失败')
    }
  } catch (error) {
    ElMessage.error('提交失败，请稍后重试')
  }
}
</script>

<template>
  <div class="main-container">
    <!-- 顶部导航栏 -->
    <header class="header">
      <div class="header-content">
        <div class="header-left">
          <router-link to="/" class="logo-link">
            <h1 class="title">MCP SPACE</h1>
          </router-link>
        </div>
        <div class="header-right">
          <router-link 
            to="/use" 
            class="usage-link"
          >
            使用方法
          </router-link>
          <button class="submit-btn" @click="showSubmitDialog = true">
            <span class="submit-icon">➕</span>
            提交MCP
          </button>
        </div>
      </div>
    </header>
    <!-- 主体内容 -->
    <div class="main-content">
      <div class="content-wrapper">
        <router-view/>
      </div>
    </div>

    <!-- 提交MCP弹窗 -->
    <SubmitMCPDialog
      v-model:visible="showSubmitDialog"
      @submit="handleSubmit"
    />
  </div>
</template>

<style scoped>
/* 隐藏滚动条但保持滚动功能 */
::-webkit-scrollbar {
  display: none;
}

/* Firefox */
* {
  scrollbar-width: none;
}

.main-container {
  height: 98vh;
  background: linear-gradient(135deg, #ffffff 0%, #fcfcfc 50%, #fafafa 100%);
  background-attachment: fixed;
  width: 100%;
  position: relative;
  overflow: hidden;
  -ms-overflow-style: none; /* IE and Edge */
  display: flex;
  flex-direction: column;
}

.main-container::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    radial-gradient(circle at 20% 35%, rgba(230, 225, 220, 0.025) 0%, transparent 50%),
    radial-gradient(circle at 75% 44%, rgba(220, 215, 210, 0.025) 0%, transparent 40%),
    url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23CCCCCC' fill-opacity='0.12'%3E%3Cpath d='M60 56.7v-6.7h-3.3v6.7h-6.7v3.3h6.7v6.7h3.3V60h6.7v-3.3h-6.7zm0-50V0h-3.3v6.7h-6.7v3.3h6.7v6.7h3.3v-6.7h6.7V6.7h-6.7zM10 56.7v-6.7H6.7v6.7H0v3.3h6.7v6.7h3.3V60h6.7v-3.3h-6.7zM10 6.7V0H6.7v6.7H0v3.3h6.7v6.7h3.3v-6.7h6.7V6.7h-6.7z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  z-index: 0;
  opacity: 0.95;
  pointer-events: none;
}

.main-container::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  backdrop-filter: blur(0.3px);
  pointer-events: none;
  z-index: 0;
}

.header {
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  height: 64px;
}

.header-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo-link {
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.title {
  font-size: 20px;
  font-weight: 800;
  margin: 0;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
  transition: filter 0.2s ease;
}

.logo-link:hover .title {
  filter: brightness(1.1) saturate(1.2);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.usage-link {
  color: #6366f1;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.3s ease;
}

.usage-link:hover {
  color: #4f46e5;
  text-decoration: underline;
}

.submit-btn {
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  border: none;
  color: white;
  padding: 8px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  line-height: 1;
  letter-spacing: 0.5px;
  position: relative;
  overflow: hidden;
}

.submit-btn:hover {
  background: linear-gradient(90deg, #818cf8, #9333ea);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
  transform: translateY(-1px);
}

.submit-btn:active {
  background: linear-gradient(90deg, #4f46e5, #7c3aed);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
  transform: translateY(1px);
}

.submit-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  transition: left 0.8s;
}

.submit-btn:hover::before {
  left: 100%;
}

.submit-icon {
  font-size: 16px;
  display: flex;
  align-items: center;
  color: white;
}

.main-content {
  flex: 1;
  padding: 88px 24px 24px;
  max-width: 1440px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  -ms-overflow-style: none;
  width: 100%;
}

.content-wrapper {
  background-color: transparent;
  border-radius: 16px;
  padding: 32px;
  min-height: calc(100% - 24px);

  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
  -ms-overflow-style: none;
}

.content-wrapper::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%);
  pointer-events: none;
}

/* 确保在移动端也有好的显示效果 */
@supports not (backdrop-filter: blur(8px)) {
  .content-wrapper {
    background-color: rgba(255, 255, 255, 0.7);
  }
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
  .header-content {
    padding: 0 16px;
    height: 56px;
  }

  .title {
    font-size: 18px;
  }
  
  .usage-link {
    font-size: 13px;
  }

  .submit-btn {
    padding: 6px 12px;
    font-size: 13px;
  }

  .main-content {
    padding: 72px 16px 16px;
  }

  .content-wrapper {
    padding: 20px;
    border-radius: 12px;
    margin-left: -50px;
  }
}
</style>